<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
<!-- creator-code-completion.qdoc -->
  <title>Completing Code | Qt Creator Manual</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="index.html">Qt Creator Manual</a></td><td >Completing Code</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="index.html">Qt Creator Manual 4.11.1</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
  <link rel="prev" href="creator-checking-code-syntax.html" />
  <link rel="next" href="creator-indenting-code.html" />
<p class="naviNextPrevious headerNavi">
<a class="prevPage" href="creator-checking-code-syntax.html">Checking Code Syntax</a>
<span class="naviSeparator">  &#9702;  </span>
<a class="nextPage" href="creator-indenting-code.html">Indenting Text or Code</a>
</p><p/>
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#summary-of-available-types">Summary of Available Types</a></li>
<li class="level1"><a href="#completing-code-snippets">Completing Code Snippets</a></li>
<li class="level2"><a href="#editing-code-snippets">Editing Code Snippets</a></li>
<li class="level2"><a href="#adding-and-editing-snippets">Adding and Editing Snippets</a></li>
<li class="level2"><a href="#removing-snippets">Removing Snippets</a></li>
<li class="level2"><a href="#resetting-snippets">Resetting Snippets</a></li>
<li class="level1"><a href="#completing-nim-code">Completing Nim Code</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Completing Code</h1>
<span class="subtitle"></span>
<!-- $$$creator-completing-code.html-description -->
<div class="descr"> <a name="details"></a>
<p>As you write code, Qt Creator suggests properties, IDs, and code snippets to complete the code. It provides a list of context-sensitive suggestions to the statement currently under your cursor. Press <b>Tab</b> or <b>Enter</b> to accept the selected suggestion and complete the code.</p>
<p>The following image displays suggestions for completing C++ code:</p>
<p class="centerAlign"><img src="images/qtcreator-codecompletion.png" alt="" /></p><p>The following image displays suggestions for completing QML code:</p>
<p class="centerAlign"><img src="images/qml-code-completion.png" alt="" /></p><p>To open the list of suggestions at any time, press <b>Ctrl+Space</b>. If only one option is available, Qt Creator inserts it automatically.</p>
<p>When completion is invoked manually, Qt Creator completes the common prefix of the list of suggestions. This is especially useful for classes with several similarly named members. To disable this functionality, uncheck <b>Autocomplete common prefix</b> in the code completion preferences. Select <b>Tools</b> &gt; <b>Options</b> &gt; <b>Text Editor</b> &gt; <b>Completion</b>.</p>
<p>By default, code completion does not consider case. To apply full or first-letter case-sensitivity, select <b>Full</b> or <b>First Letter</b> in the <b>Case-sensitivity</b> field.</p>
<a name="summary-of-available-types"></a>
<h2 id="summary-of-available-types">Summary of Available Types</h2>
<p>The following table lists available types for code completion and icon used for each.</p>
<div class="table"><table class="generic">
 <thead><tr class="qt-style"><th >Icon</th><th >Description</th></tr></thead>
<tr valign="top" class="odd"><td ><img src="images/class.png" alt="" /></td><td >A class</td></tr>
<tr valign="top" class="even"><td ><img src="images/enum.png" alt="" /></td><td >An enum</td></tr>
<tr valign="top" class="odd"><td ><img src="images/enumerator.png" alt="" /></td><td >An enumerator (value of an enum)</td></tr>
<tr valign="top" class="even"><td ><img src="images/func.png" alt="" /></td><td >A function</td></tr>
<tr valign="top" class="odd"><td ><img src="images/func_priv.png" alt="" /></td><td >A private function</td></tr>
<tr valign="top" class="even"><td ><img src="images/func_prot.png" alt="" /></td><td >A protected function</td></tr>
<tr valign="top" class="odd"><td ><img src="images/var.png" alt="" /></td><td >A variable</td></tr>
<tr valign="top" class="even"><td ><img src="images/var_priv.png" alt="" /></td><td >A private variable</td></tr>
<tr valign="top" class="odd"><td ><img src="images/var_prot.png" alt="" /></td><td >A protected variable</td></tr>
<tr valign="top" class="even"><td ><img src="images/signal.png" alt="" /></td><td >A signal</td></tr>
<tr valign="top" class="odd"><td ><img src="images/slot.png" alt="" /></td><td >A slot</td></tr>
<tr valign="top" class="even"><td ><img src="images/slot_priv.png" alt="" /></td><td >A private slot</td></tr>
<tr valign="top" class="odd"><td ><img src="images/slot_prot.png" alt="" /></td><td >A protected slot</td></tr>
<tr valign="top" class="even"><td ><img src="images/keyword.png" alt="" /></td><td >A C++ keyword</td></tr>
<tr valign="top" class="odd"><td ><img src="images/snippet.png" alt="" /></td><td >A C++ code snippet</td></tr>
<tr valign="top" class="even"><td ><img src="images/element.png" alt="" /></td><td >A QML type</td></tr>
<tr valign="top" class="odd"><td ><img src="images/qmlsnippet.png" alt="" /></td><td >A QML code snippet</td></tr>
<tr valign="top" class="even"><td ><img src="images/macro.png" alt="" /></td><td >A macro</td></tr>
<tr valign="top" class="odd"><td ><img src="images/namespace.png" alt="" /></td><td >A namespace</td></tr>
</table></div>
<a name="completing-code-snippets"></a>
<h2 id="completing-code-snippets">Completing Code Snippets</h2>
<p>Code snippets can consist of multiple variables that you specify values for. Select an item in the list and press <b>Tab</b> or <b>Enter</b> to complete the code. Press <b>Tab</b> to move between the variables and specify values for them. When you specify a value for a variable, all instances of the variable within the snippet are renamed.</p>
<p>The following image shows a C++ code snippet:</p>
<p class="centerAlign"><img src="images/qmldesigner-code-completion.png" alt="&quot;Completing C++ code&quot;" /></p><p>The following image shows a QML code snippet:</p>
<p class="centerAlign"><img src="images/qml-code-snippet.png" alt="" /></p><a name="editing-code-snippets"></a>
<h3 id="editing-code-snippets">Editing Code Snippets</h3>
<p>Code snippets specify code constructs. You can add, modify, and remove snippets in the snippet editor. To open the editor, select <b>Tools</b> &gt; <b>Options</b> &gt; <b>Text Editor</b> &gt; <b>Snippets</b>.</p>
<p>The following image shows built-in C++ code snippets:</p>
<p class="centerAlign"><img src="images/qtcreator-edit-code-snippets.png" alt="&quot;C++ snippet options&quot;" /></p><p>The following image shows built-in QML code snippets:</p>
<p class="centerAlign"><img src="images/qml-snippet-editor.png" alt="" /></p><p>Qt Creator provides you with built-in snippets in the following categories:</p>
<ul>
<li>Text snippets, which can contain any text string. For example, code comments</li>
<li>C++ code snippets, which specify C++ code constructs</li>
<li>CMake code snippets that you can use when editing <code>CMakeLists.txt</code> files in the CMake editor</li>
<li>QML code snippets, which specify QML code constructs</li>
<li>Nim code snippets, which specify Nim code constructs</li>
</ul>
<a name="adding-and-editing-snippets"></a>
<h3 id="adding-and-editing-snippets">Adding and Editing Snippets</h3>
<p>Select a snippet in the list to edit it in the snippet editor. To add a new snippet, select <b>Add</b>. Specify a trigger and, if the trigger is already in use, an optional variant, which appear in the list of suggestions when you write code. Also specify a text string or C++ or QML code construct in the snippet editor, depending on the snippet category. You can use <a href="creator-build-settings.html#using-qt-creator-variables">predefined variables</a> in snippets. The snippet editor provides you with:</p>
<ul>
<li>Highlighting</li>
<li>Indentation</li>
<li>Parentheses matching</li>
<li>Basic code completion</li>
</ul>
<p>Specify the variables for the snippets in the following format:</p>
<pre class="cpp">

  $variable$

</pre>
<p>Specify Qt Creator variables in the following format:</p>
<pre class="cpp">

  <span class="operator">%</span>{variable}

</pre>
<p>For example, the following variable expands to the name of the current project: <code>%{CurrentProject:Name}</code>.</p>
<p>Use unique variable names within a snippet, because all instances of a variable are renamed when you specify a value for it.</p>
<p>To determine the case of values you enter in snippets, use the following modifiers:</p>
<ul>
<li><code>:c</code> converts the initial letter of the string to upper case</li>
<li><code>:l</code> converts the string to lower case</li>
<li><code>:u</code> converts the string to upper case</li>
</ul>
<p>For example, add the following line to the <code>class</code> snippet to specify that the function name is converted to all lower case characters regardless of how you specify the value of the <code>$name$</code> variable:</p>
<pre class="cpp">

  <span class="type">void</span> $name:l$() {}

</pre>
<p class="centerAlign"><img src="images/qtcreator-snippet-modifiers.png" alt="" /></p><p>The snippet editor does not check the syntax of the snippets that you edit or add. However, when you use the snippets, the code editor marks any errors by underlining them in red.</p>
<p>To discard the changes you made to a built-in snippet, select <b>Revert Built-in</b>.</p>
<a name="removing-snippets"></a>
<h3 id="removing-snippets">Removing Snippets</h3>
<p>Several similar built-in snippets might be provided for different use cases. To make the list of suggestions shorter when you write code, remove the built-in snippets that you do not need. If you need them later, you can restore them.</p>
<p>To remove snippets, select a snippet in the list, and then select <b>Remove</b>. To restore the removed snippets, select <b>Restore Removed Built-ins</b>.</p>
<a name="resetting-snippets"></a>
<h3 id="resetting-snippets">Resetting Snippets</h3>
<p>To remove all added snippets and to restore all removed snippets, select <b>Reset All</b>.</p>
<p><b>Note: </b>If you now select <b>OK</b> or <b>Apply</b>, you permanently lose all your own snippets.</p><a name="completing-nim-code"></a>
<h2 id="completing-nim-code">Completing Nim Code</h2>
<p>You can use the <a href="https://nim-lang.org/docs/nimsuggest.html">Nimsuggest</a> tool to query <code>.nim</code> source files and obtain suggestions for code completion.</p>
<p>To use Nimsuggest, you must install it on the development PC. Then select <b>Tools</b> &gt; <b>Options</b> &gt; <b>Nim</b> &gt; <b>Tools</b>, and enter the path to the tool executable in the <b>Path</b> field.</p>
</div>
<!-- @@@creator-completing-code.html -->
<p class="naviNextPrevious footerNavi">
<a class="prevPage" href="creator-checking-code-syntax.html">Checking Code Syntax</a>
<span class="naviSeparator">  &#9702;  </span>
<a class="nextPage" href="creator-indenting-code.html">Indenting Text or Code</a>
</p>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
